package com.example.admin_test.common.Interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Slf4j
@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 获取session， 判断session用户信息是否存在
        Object user = request.getSession().getAttribute("userInfo");
//        if(user == null){
//            // 未登录
//            log.debug("未登录请求：" + request.getRequestURI());
//            response.sendRedirect(request.getContextPath() + "/");//没有登陆登录信息拦截后重定向道登录界面
//            return false;
//        }
        log.debug("放行请求：" + request.getRequestURI());
        return true;
    }
}
